<template>
    <div class="login-wrap">
        <div class="top">
            <div class="header">
                <a href="/">
                    <span class="title">Loongson Project</span>
                </a>
            </div>
            <div class="desc">
                Loongson Project基于龙芯的项目管理申报平台
                <span class="login-tips"> &copy; 2020 云龙-云征  </span>
            </div>
        </div>
        <div class="ms-login">
            <div class="ms-title">登录</div>
            <el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
                <el-form-item prop="username">
                    <el-input v-model="param.username" placeholder="phone number">
                        <el-button slot="prepend" icon="el-icon-phone"></el-button>
                    </el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input
                            type="password"
                            placeholder="password"
                            v-model="param.password"
                            @keyup.enter.native="submitForm()"
                    >
                        <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
                    </el-input>
                </el-form-item>
                <div class="login-btn">
                    <el-button type="primary" @click="submitForm()">登录</el-button>
                </div>
                <div class="register-tips" @click="this.gotoRegister">没有账号？去注册</div>
            </el-form>
        </div>
    </div>
</template>

<script>
  export default {
    name: 'login',
    props: {},
    data: function () {
      return {
        identifyCode: '',
        param: {
          username: '',
          password: '',
        },
        rules: {
          username: [{required: true, message: '请输入手机号', trigger: 'blur'}],
          password: [{required: true, message: '请输入密码', trigger: 'blur'}],
        },
      };
    },
    methods: {
      submitForm: function () {
        this.$refs.login.validate(valid => {
          if (valid) {
            this.$http.post('/user/login',{
                userPhone: this.param.username,
                password: this.param.password,
            })
              .then( res => {
                if (res) {
                  this.$message.success('登录成功');
                  this.$router.push('/');
                  console.log(res.data);
                  window.localStorage.setItem('token', res.data);
                }
              })
          } else {
            this.$message.error('请输入手机号和密码');
            console.log('error submit!!');
            return false;
          }
        });
      },
      gotoRegister: function () {
        this.$router.push('/register');
      }
    },
    mounted () {},
  };
</script>

<style lang="less" scoped>
    .s-canvas {
        width: 100px;
        height: 38px;
        cursor: pointer;
    }
    .s-canvas canvas{
        margin-top: 1px;
        margin-left: 8px;
    }
    .login-wrap {
        position: relative;
        width: 100%;
        height: 100%;
        background-image: url(../../assets/img/login-bg.jpg);
        background-size: 100%;
    }

    .ms-title {
        width: 100%;
        line-height: 50px;
        text-align: center;
        font-size: 20px;
        color: #fff;
        border-bottom: 1px solid #ddd;
    }

    .ms-login {
        position: absolute;
        left: 50%;
        top: 58%;
        width: 350px;
        margin: -190px 0 0 -175px;
        border-radius: 5px;
        background: rgba(255, 255, 255, 0.3);
        overflow: hidden;
    }

    .ms-content {
        padding: 30px 30px;
    }

    .login-btn {
        text-align: center;
    }

    .register-tips {
        float: right;
        font-size: 12px;
        line-height: 14px;
        color: #fff;
        cursor: pointer;
    }

    .login-btn button {
        width: 100%;
        height: 36px;
        margin-bottom: 10px;
    }

    .login-tips {
        color: rgba(0, 0, 0, 0.45);
        font-size: 12px;
        line-height: 30px;
        text-align: center;
    }

    .top {
        padding-top: 150px;
        text-align: center;

    .header {
        height: 44px;
        line-height: 44px;
        background-color: transparent;

    .title {
        font-size: 33px;
        color: rgba(0, 0, 0, .85);
        font-family: "Chinese Quote", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
        font-weight: 600;
        position: relative;
        top: 2px;
    }

    }
    .desc {
        font-size: 14px;
        color: rgba(0, 0, 0, 0.45);
        margin-top: 15px;
        margin-bottom: 40px;
    }

    }
</style>
